package com.guli.gulimall.gulimallware.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.guli.gulimall.gulimallware.vo.MergeVo;
import com.guli.gulimall.gulimallware.vo.PurchaseDoneVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.guli.gulimall.gulimallware.entity.PurchaseEntity;
import com.guli.gulimall.gulimallware.service.PurchaseService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;



/**
 * 采购信息
 *
 * @author zouzhi
 * @email 1245268075@qq.com
 * @date 2022-04-03 15:08:09
 */
@RestController
@RequestMapping("gulimallware/purchase")
@Api("采购需求单处理")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    @PostMapping("/merge")
    @ApiOperation(value = "合并采购单",notes = "将采购单分配给某人去处理")
    public  R merge(@RequestBody MergeVo vo){
        System.out.println(vo.toString());

        return  purchaseService.mergePurchase(vo);
    }
    @GetMapping("/unreceive/list")
    @ApiOperation("查询未分配和已经分配的采购单")
    public R unreceivelist(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPageUnreceived(params);
        return R.ok().put("page", page);
    }
    @PostMapping("/received")
    @ApiOperation(value = "外卖小哥领取采购单",notes = "需要注意的是，该部分不属于后台管理系统，属于外卖小哥的客户端接口")
    public R receivelist(@RequestBody List<Long> ids){
        return purchaseService.receivelist(ids);
    }
    @PostMapping("/done")
    @ApiOperation(value = "外卖小哥完成采购单",notes = "需要注意的是，该部分不属于后台管理系统，属于外卖小哥的客户端接口")
    public R done(@RequestBody PurchaseDoneVo purchaseDoneVo){

        return purchaseService.done(purchaseDoneVo);
    }
    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		PurchaseEntity purchase = purchaseService.getById(id);

        return R.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody PurchaseEntity purchase){
        purchase.setUpdateTime(new Date());
        purchase.setCreateTime(new Date());
		purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody PurchaseEntity purchase){
        purchase.setUpdateTime(new Date());
        System.out.println(new Date());
		purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
